package com.itheima.services;


import com.itheima.mapper.BusinessMapper;
import com.itheima.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Book;
import java.util.List;

@Service
public class BusinessServicesA implements BusinessServices{
    @Autowired
    public BusinessMapper businessMapper;

    @Override
    public User Blogin(User user) {
        User user1=businessMapper.Blogin(user);
        return user1;
    }

    @Override
    public List<Emp> showEmp() {
        List<Emp> emps=businessMapper.showEmp();
        return emps;
    }

    @Override
    public List<Emp> conShowEmp(String name) {
        List<Emp> emps=businessMapper.conShowEmp(name);
        return emps;
    }

    @Override
    public Emp changeEmp1(Long empId) {
        Emp emp=businessMapper.changeEmp1(empId);
        return emp;
    }

    @Override
    public Result changeEmp2(Emp emp) {
        if(emp.getPhone().length()!=11){
            return new Result(0,"Error_Num",null);
        }
        businessMapper.changeEmp2(emp);
        return Result.success();
    }

    @Override
    public void changeState(String state,Long empId) {
        if(state.equals("禁用")){
            state="启用";
        }else if(state.equals("启用")){
            state="禁用";
        }
        businessMapper.changeState(state,empId);
    }

    @Override
    public Result addEmp(Emp emp) {
        if(emp.getEmpName().length()>16||emp.getEmpName().length()<2){
            return new Result(0,"Error_Name",null);
        }
        if(emp.getPhone().length()!=11){
            return new Result(0,"Error_Num",null);
        }
        if(emp.getPassword().length()<4||emp.getPassword().length()>20){
            return new Result(0,"Error_Password",null);
        }
        emp.setState("禁用");
        businessMapper.addEmp(emp);
        return Result.success();
    }

    @Override
    public List<FoodCategory> showCategory() {
        List<FoodCategory>categories=businessMapper.showCategory();
        return categories;
    }

    @Override
    public List<Food> showFood() {
        List<Food> foods=businessMapper.showFood();
        return foods;
    }

    @Override
    public Food changeFood1(Long foodId) {
        Food food =businessMapper.changeFood1(foodId);
        return food;
    }

    @Override
    public void changeFood2(Food food) {
        businessMapper.changeFood2(food);
    }

    @Override
    public List<Food> conShowFood(Food food) {
        List<Food>foods=businessMapper.conShowFood(food);
        return foods;
    }

    @Override
    public void deleteFood(Long foodId) {
        businessMapper.deleteFood(foodId);
    }

    @Override
    public void addFood(Food food) {
        food.setFoodState("下架");
        businessMapper.addFood(food);
    }

    @Override
    public void changeFoodState(Long foodId,String foodState) {
        if(foodState.equals("下架")){
            foodState="未下架";
        }else{
            foodState="下架";
        }
        System.out.println(foodState);
        businessMapper.changeFoodState(foodId,foodState);
    }

    @Override
    public PageBean showOrders(OrderForm form, int currentPage, int pageSize) {
        int count=businessMapper.conCount(form);
        int start=(currentPage-1)*pageSize;
        List<OrdersList>ordersLists=businessMapper.conPage(form.getOrderId(),form.getOrderState(),form.getUserName(),start,pageSize);
        PageBean pageBean=new PageBean(count,ordersLists);
        return pageBean;
    }

    @Override
    public void cancelOrder(Long orderId) {
        businessMapper.cancelOrder(orderId);
    }

    @Override
    public void acceptOrder(Long orderId) {
        businessMapper.acceptOrder(orderId);
    }

    @Override
    public FoodCategory changeCategory1(Long categoryId) {
        FoodCategory category=businessMapper.changeCategory1(categoryId);
        return category;
    }

    @Override
    public void changeCategory2(FoodCategory categoryForm) {
        businessMapper.changeCategory2(categoryForm);
    }

    @Override
    public void deleteCategory(Long categoryId) {
        businessMapper.deleteCategory(categoryId);
    }

    @Override
    public void addCategory(String category) {
        businessMapper.addCategory(category);
    }
}
